import * as _ from "lodash"

export class OptionSelection {
  private name_id: string
  public name: string
  private value_id: string
  public value: string

  public get nameId() {
    return this.name_id
  }

  public set nameId(nameId) {
    this.name_id = nameId
  }

  public get valueId() {
    return this.value_id
  }

  public set valueId(valueId) {
    this.value_id = valueId
  }
}

export class OptionSelections {

  public static equals(a: OptionSelection | OptionSelection[], b: OptionSelection | OptionSelection[]): boolean {
    if ((_.isArray(a) && !_.isArray(b))
      || (!_.isArray(a) && _.isArray(b))
      || (_.isUndefined(a) || _.isUndefined(b))) {
      return false
    }
    if (_.isArray(a) && _.isArray(b)) {
      for (const a1 of a) {
        let notEquals = true
        for (const b1 of b) {
          if (this.equals(a1, b1)) {
            notEquals = false
            break
          }
        }
        if (notEquals) {
          return false
        }
      }
      return true
    }
    const a1 = a as OptionSelection
    const b1 = b as OptionSelection
    return a1.name === b1.name && a1.value === b1.value
  }
}
